/*
Content: Help dataset to construct occupational scores for Table G.1
Paper: "Immigrants Return Intentions and Labor Market Behavior when the Home Country is Unsafe"
Journal: Journal of Labor Economics
Authors: Jacopo Bassetto, Teresa Freitas-Monteiro
Version: 1.1 - May 8th, 2025
*/

********************************************************************************
* LOAD DATASET
********************************************************************************

	// LOAD HERE A PREPARED SIAB FOR ONLY GERMANS (with nationality == 0)

********************************************************************************
* CREATE VARIABLES FOR THE COLLAPSING 
********************************************************************************
	
gen year = year(begepi)
	
tab educ_max, gen(educ_max_d)

gen ln_wage_defl = ln(wage_defl)

tab haupttask, gen(haupttask_d)

********************************************************************************
* COLLAPSE AT THE YEAR, STATE, 5 digits OCCUPATION 
********************************************************************************

keep if quelle == 1 & azubi != 1		//keeping only employed and not azubi

foreach occ in ieb_beruf_kons_num ieb_beruf_num wz08_kons_num {
	
preserve	

keep if !inlist(`occ',-9,-5,-7)
collapse (mean) educ_max_d1 educ_max_d2 educ_max_d3 tentgelt ln_hwage lnwage haupttask_d1 haupttask_d2 haupttask_d3 haupttask_d4 haupttask_d5 regulindex, by(ao_land year `occ')


save "$help/occupational_scores_2perc_germans_bula_year_`occ'.dta", replace

restore

preserve

keep if !inlist(`occ',-9,-5,-7)
collapse (mean) educ_max_d1 educ_max_d2 educ_max_d3 tentgelt ln_hwage lnwage haupttask_d1 haupttask_d2 haupttask_d3 haupttask_d4 haupttask_d5 regulindex, by(year `occ')

save "$help/occupational_scores_2perc_germans_year_`occ'.dta", replace

restore


preserve

keep if !inlist(`occ',-9,-5,-7)
collapse (mean) educ_max_d1 educ_max_d2 educ_max_d3 tentgelt ln_hwage lnwage haupttask_d1 haupttask_d2 haupttask_d3 haupttask_d4 haupttask_d5 regulindex, by(`occ')

save "$help/occupational_scores_2perc_germans_`occ'.dta", replace

restore

}

